package com.csjbot.snowbot_rogue.activity.settings;

import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;

import com.csjbot.csjbase.base.CsjBaseActivity;
import com.csjbot.csjbase.log.Csjlogger;
import com.csjbot.snowbot_rogue.Events.AIUIEvent;
import com.csjbot.snowbot_rogue.Events.EventsConstants;
import com.csjbot.snowbot_rogue.Events.ExpressionEvent;
import com.csjbot.snowbot_rogue.R;
import com.csjbot.snowbot_rogue.platform.SnowBotManager;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


public class SettingsHWTestActivity extends CsjBaseActivity {
    private SnowBotManager snowBotManager = SnowBotManager.getInstance();
    private TextView textView;
    private ScrollView scrollView;

    private int faceType = 0;

    @Override
    public boolean useEventBus() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public boolean onAIUIEvent(AIUIEvent event) {
        Csjlogger.debug("AIUIEvent " + event.getTag());
        boolean isCaptured = true;
        switch (event.getTag()) {
            case EventsConstants.SerialportEvents.ACTION_SERIAL_SEND_OK:
                SerialSendOkRec();
                break;
            default:
                isCaptured = false;
                break;
        }
        return isCaptured;
    }

    private void SerialSendOkRec() {
        textView.append("发送成功\n");
        scrollView.fullScroll(View.FOCUS_DOWN);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public void changeExpression(View view) {
        faceType += 1;
        if (faceType > 9) {
            faceType = 0;
        }
        postEvent(new ExpressionEvent(faceType));
    }

    public void sendSensorAll(View view) {
    }

    public void turnOffAirCon(View view) {
    }

    public void turnOnAirCon(View view) {
//        postEvent(new AIUIEvent(EventsConstants.AIUIEvents.AIUI_EVENT_TOUCH_GET));
    }

    public void swingDoubleArm(View view) {
        snowBotManager.swingDoubleArm((byte) 0x04);
    }

    public void pageFinished(View view) {
        finish();
    }

    public void changeFaceColor(View view) {
//        startActivity(new Intent(this, SettingsChangeFaceActivity.class));
    }

    @Override
    public void afterViewCreated(Bundle savedInstanceState) {
        textView = (TextView) findViewById(R.id.TextView);
        scrollView = (ScrollView) findViewById(R.id.ScrollView);
    }

    @Override
    public void setListener() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_settings_hw_test;
    }
}
